Skip to content

feat(v6): require Rspack 2 - #1490

Open
dannyhw wants to merge 12 commits into
dannyhw/v6from
dannyhw/rspack-2
Open

dannyhw wants to merge 12 commits into
dannyhw/v6from
dannyhw/rspack-2

Conversation

@dannyhw

@dannyhw dannyhw commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #1487 (dannyhw/v6).

Summary

Re.Pack 6 requires @rspack/core 2 (peer >=2) and drops Rspack 1. There's no runtime branching on the Rspack major. The change maps the options Rspack 2 renamed or moved, fixes the type fallout, and removes the Rspack 1 workarounds. webpack is unaffected. New projects from @callstack/repack-init get @rspack/core@^2.

Mapped options

  • experiments.parallelLoader: Rspack 2 removed it, so Re.Pack no longer sets it. Loaders run in parallel when their rule sets parallel: true, which the templates and tester apps already do.
    • The babel-swc-loader warning about it can no longer fire, so the warning and its hideParallelModeWarning option are removed.
  • experiments.cache: Rspack 2 ignores it silently, so REPACK_EXPERIMENTAL_CACHE produced no persistent cache. It now sets top-level cache: { type: 'persistent' }.
    • --reset-cache reads top-level cache for both bundlers. resetPersistentCache lost its per-bundler overloads and casts.
  • exportsPresence: Rspack 2's default is 'error', which fails on missing-export imports that React Native itself ships (React.unstable_Activity in renderApplication.js). Re.Pack sets module.parser.javascript.exportsPresence: 'auto' for Rspack.
  • RSPACK_PROFILE: it crashed start because published v2 binaries have no perfetto layer. It now defaults to the logger layer. The pre-1.4 profile handler is gone.

Rspack 2 behaviour changes handled

  • bundle --json: stats.toJson() now leaves out assets, chunks, chunk groups, entrypoints and modules unless asked for, even with preset: 'normal'. With no stats config, Re.Pack requests them explicitly. User presets are passed through.
  • Production source maps: absoluteResourcePath is now <context>/../../... and isn't resolved. SourceMapPlugin normalizes it.
  • repack-expo: the Module Federation runtime data: module's resource path is now percent-encoded. The Expo source map fix matches the encoded form.

Types

  • babel-swc-loader: SwcLoaderOptions is now a union on detectSyntax, so the loader uses its own non-union SwcConfig.
  • assetsLoader: it reads through small promise wrappers typed against InputFileSystem, because util.promisify picks the wrong overload of the v2 types.
  • RepackTargetPlugin: devServer is now false | DevServer, so it's narrowed before reading hot.

Rspack 1 workarounds removed

  • the profile handler for Rspack < 1.4
  • the SWC minimizer special case for 1.4.11; the Rspack minimizer is always Terser now
  • the parallel-loader rootContext workaround and the @rspack/core fallback lookup for SWC. Rspack 2 passes parallel loaders the right rootContext and _compiler.rspack.experiments.swc (checked in serial and parallel mode).

Tests and infra

  • Jest loads the ESM-only core through a custom test environment (jest.environment.js plus a moduleNameMapper bridge).
  • Integration markers and snapshots follow Rspack 2's output:
    • runtime module banners are // repack/polyfills
    • module factories use method shorthand
    • with MF v2, the polyfills runtime module now comes before embed_federation_runtime. MF still initializes in __webpack_require__.x(), after the polyfills, in both the test bundle and the real host bundle (MF 2.9.2).
  • New tests:
    • the cache config and cache reset
    • the exportsPresence default
    • the stats fallback
    • SourceMapPlugin path normalization: a real Rspack compile that fails without the fix
  • The catalog pin is now ^2.2.8. The old "1.6.2+ breaks MF v2 polyfill ordering; 1.6.4+ fails typecheck" notes don't apply to 2.2.8. @swc/helpers is ^0.5.23, the Rspack 2 peer.
  • One CI lane is enough with a single Rspack major, so CI is unchanged.

Docs

  • parallelLoader → per-rule parallel: true in the configuration guide and the babel-loader / babel-swc-loader pages
  • the Re.Pack defaults now list exportsPresence
  • new Rspack 2 section in the Re.Pack 5 migration guide
  • agent_context design doc rewritten for the single-major approach

Known issue (upstream, not fixed here)

In tester-app production bundles, 9 of about 1100 source map sources point one directory too shallow, e.g. apps/packages/repack/dist/modules/InitializeScriptManager.js. The affected sources are Re.Pack's own runtime modules, reached through the workspace symlink apps/tester-app/node_modules/@callstack/repack -> ../../../../packages/repack.

  • Rspack 2 itself reports the wrong relative resourcePath for these modules. The wrong path is what you get by resolving the link target against the link instead of its directory.
  • Rspack 1.6 got them right, except one require.context module that was already wrong on 1.6.
  • Dev-server source maps aren't affected: 1220/1220 [projectRoot] sources resolve.
  • I couldn't reproduce it outside tester-app yet, so it needs a minimal repro before it goes upstream.

Verification

Run on Rspack 2.2.8, Node 26:

Checks: pnpm build, pnpm typecheck, pnpm lint:ci and pnpm test, all with --force. All pass, including:

Suite Result
repack (Jest) 345
integration (Rspack + webpack) 122
repack-expo 125

Bundles:

  • tester-app production bundles: Rspack iOS + Android, webpack iOS + Android
  • MF v2 bundles from apps/tester-federation-v2/configs/*.mts, iOS + Android each: Rspack host, mini and expo-host-widget, webpack host and mini
  • bundle --json writes assets/chunks/modules again, and --stats minimal is respected

Dev server:

  • start serves iOS + Android
  • REPACK_EXPERIMENTAL_CACHE=1 writes node_modules/.cache/rspack: cold compile 11.2s, warm 2.7s
  • --reset-cache deletes that directory
  • RSPACK_PROFILE=OVERVIEW emits logger traces with no perfetto crash

Native apps: tester-app Debug ran against the Rspack 2 dev server on the iOS simulator (iPhone 17 Pro, iOS 27) and the Android emulator (Pixel 9).

  • Both loaded, including async chunks.
  • Editing src/App.tsx hot-updated the screen in place on both platforms, with component state kept.
    • iOS fetched only main.<hash>.hot-update.json, with no bundle reload.
    • Android logged [HMRClient] Processing bundle update.

I also checked out the first commit on its own: it typechecks and passes its Jest suite (340).

@vercel

vercel Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
repack-website Ready Ready Preview Nov 9, 2026 1:12pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f7265b5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@callstack/repack Major
@callstack/repack-init Major
@callstack/repack-plugin-expo-modules Major
@callstack/repack-plugin-nativewind Major
@callstack/repack-plugin-reanimated Major
@callstack/repack-dev-server Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Raise the @rspack/core peer to >=2 and build and test against 2.2.8.
Map the options Rspack 2 renamed or removed:

- Stop setting experiments.parallelLoader, which Rspack 2 removed.
  Parallel loading is opted into per rule with `parallel: true`. The
  babel-swc-loader warning about it could no longer fire, so it is
  removed together with the hideParallelModeWarning option.
- Rspack 2 passes parallel loaders a correct rootContext and the
  compiler's bundled SWC, so the babel-swc-loader uses both directly.
- REPACK_EXPERIMENTAL_CACHE sets and --reset-cache reads the top-level
  `cache` option, as Rspack 2 silently ignores experiments.cache.
- Fix the type fallout: a non-union SwcConfig for the babel-swc-loader,
  InputFileSystem-typed reads in the assets loader, and narrowing the
  now `false | DevServer` devServer option.

Jest loads the ESM-only core through a custom test environment, and the
integration markers and snapshots follow Rspack 2's output.

# Conflicts:
#	packages/repack/src/loaders/babelSwcLoader/babelSwcLoader.ts
#	pnpm-lock.yaml
#	tests/integration/src/loaders/react-native-parser.test.ts
Rspack 2 changed the default of module.parser.javascript.exportsPresence
to 'error', which fails builds on missing-export imports that React
Native itself ships, such as `React.unstable_Activity` in
renderApplication.js. Default it to 'auto', matching webpack and
Rspack 1. Projects can still override it.
Published Rspack 2 binaries are built without the perfetto trace layer,
so `RSPACK_PROFILE` crashed `start` unless RSPACK_TRACE_LAYER was set.
Default to the logger layer, and drop the handler for Rspack < 1.4.
The SWC minimizer was only picked for Rspack 1.4.11, which Re.Pack no
longer supports, so the minimizer no longer depends on the bundler.
Rspack 2's stats.toJson() leaves out assets, chunks, chunk groups,
entrypoints and modules unless they are asked for, even with the
`normal` preset. When the project has no stats config, request them
explicitly so `bundle --json` writes the same stats as before.
Rspack 2 joins a module's absoluteResourcePath from the context without
resolving it, so files outside the project root, such as hoisted
node_modules in a monorepo, were named `<context>/../../...` in source
maps built without a dev server. Normalize the path.
…e source

Rspack 2 percent-encodes the resource path of the Module Federation
runtime `data:` module, so the malformed `webpack://` source it produces
no longer matched the raw prefix and was not renamed to
`webpack://module-federation/virtual-runtime-<hash>.js`.
Replace experiments.parallelLoader with per-rule `parallel: true`, drop
hideParallelModeWarning, list the exportsPresence default, and add a
Rspack 2 section to the Re.Pack 5 migration guide.
…lugin snapshots

Rspack 2 inlines the MF v2 bundler runtime as a URL-encoded data: URI, which
put an absolute local path in the snapshot, and colors inlined error messages
when color output is enabled, as it is on CI.
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel

Verdict: approve

4 finding(s): 4 minor.

🟡 Minor (4)

Where Finding
packages/repack/src/commands/common/setupStatsWriter.ts:18 Rspack-only stats workaround now also overrides webpack's default stats
packages/repack/src/loaders/babelSwcLoader/babelSwcLoader.ts:104 root: projectRoot drops the babelConfig.root fallback for files at the project root
packages/repack/src/loaders/babelSwcLoader/utils.ts:92 Unchained _compiler.rspack.experiments.swc throws when backend detection falls through
packages/repack/src/plugins/SourceMapPlugin.ts:53 path.normalize rewrites non-filesystem source names, not just Rspack's unjoined path

6 findings below minor not shown (user_settings.min_severity).

Not in the reviewers' prompt (3 files)
  • pnpm-lock.yaml: generated or a lockfile, so its lines were left out
  • tests/integration/src/plugins/__snapshots__/rspack/NativeEntryPlugin.test.ts.snap: generated or a lockfile, so its lines were left out
  • tests/integration/src/plugins/__snapshots__/webpack/NativeEntryPlugin.test.ts.snap: generated or a lockfile, so its lines were left out

Reviewed with this repository's own Sentinel configuration (3c7ee5792550).

Feedback goes in the review comment threads, as a reply under the inline comment of a finding:

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Comment @apex-sentinel-staging review on this conversation to run a full review.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 4 new findings on f7265b5. The verdict and the full list are in the summary comment.

Comment on lines +18 to +27
// Rspack 2 leaves these out of `stats.toJson()` unless asked for,
// webpack includes them by default
const DEFAULT_JSON_STATS_OPTIONS = {
assets: true,
chunks: true,
chunkGroups: true,
chunkModules: true,
entrypoints: true,
modules: true,
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · Rspack-only stats workaround now also overrides webpack's default stats

A webpack project with no stats config gets chunkModules: true from the hard-coded six-key object in normalizeStatsOptions, so bundle --json output gains per-chunk nested module arrays that webpack's normal preset does not enable. bundle.ts calls normalizeStatsOptions regardless of bundler, so the Rspack-only workaround overrides webpack's default stats for all projects. Gate the workaround at the bundle.ts call site or pass the bundler in.

Details

Also raised here

Also raised at this location by persona javascript: bundle --json stats fallback now overrides webpack's own default stats too — Running bundle --json on a webpack project with no stats config used to call stats.toJson(undefined) and get webpack's own default JSON (which includes errors, warnings, hash, time, version alongside assets/chunks/modules). normalizeStatsOptions now returns the six-key DEFAULT_JSON_STATS_OPTIONS whenever options is undefined or an empty object, and the function has no bundler parameter, so the same explicit partial options object is handed to webpack's toJson — every key the comment says webpack "includes by default" but that is not listed (errors, warnings, hash, time, version, reasons…) is now filtered out of the written JSON, contradicting the PR's claim that webpack is unaffected. The new branch is also inconsistent for the neighbouring case: { assets: false } is non-empty so it passes through unchanged and still loses the six defaults for the user's own config, while {} silently gains them.

persona: senior-developer, javascript


const lazyImports = options.lazyImports ?? false;
const projectRoot = getProjectRootPath(this);
const projectRoot = this.rootContext;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · root: projectRoot drops the babelConfig.root fallback for files at the project root

A file at the project root where rootContext === context (e.g. App.tsx) now passes root: this.rootContext to both Babel and SWC calls; previously this case returned undefined and let Babel resolve the root itself. If the Babel config lives above rootContext and rootMode: 'upward' is not set, Babel now stops its config-file search at rootContext, so presets/plugins from the outer config are silently not applied. The rootContext !== context guard existed specifically to avoid this; removing it also silently changes behavior for webpack + thread-loader users, which the changeset claims are unaffected.

Suggested change
const projectRoot = this.rootContext;
const projectRoot =
this.rootContext !== this.context ? this.rootContext : undefined;

Suggested change

Either restore the rootContext !== context guard (or the babelConfig.root ?? undefined fallback) for the ambiguous case, or state in the v6 migration guide that babel-swc-loader now always pins Babel/SWC root to rootContext so monorepo projects with an outer Babel config must set rootMode: 'upward'.

Details

persona: senior-developer, maintainability

Comment on lines 92 to +98
async function getSwcModule(loaderContext: LoaderContext): Promise<Swc | null> {
const projectRoot = getProjectRootPath(loaderContext) ?? process.cwd();
const isWebpack = isWebpackBackend(loaderContext);
if (!isWebpack) {
// happy path - rspack & exposed swc
// use optional chaining to avoid type errors when using parallel loader
if (loaderContext._compiler.rspack?.experiments?.swc) {
return loaderContext._compiler.rspack.experiments.swc;
}
// fallback to checking for `@rspack/core` installed in the project
// use optional chaining to avoid type errors when there is no experiments.swc
const rspackCorePath = safelyResolve('@rspack/core', projectRoot);
if (rspackCorePath && !isWebpack) {
const rspack = await importDefaultESM<typeof Rspack>(rspackCorePath);
return rspack.experiments?.swc ?? null;
}
if (!isWebpackBackend(loaderContext)) {
// Rspack exposes its bundled SWC, also to parallel loaders
return loaderContext._compiler.rspack.experiments.swc;
}
// fallback to checking for `@swc/core` installed in the project
// this can be in both webpack & rspack projects
const swcCorePath = safelyResolve('@swc/core', projectRoot);
// webpack - use `@swc/core` installed in the project
const swcCorePath = safelyResolve('@swc/core', loaderContext.rootContext);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · Unchained _compiler.rspack.experiments.swc throws when backend detection falls through

When isWebpackBackend returns false (detection falls through) and the loader context's compiler lacks rspack or experiments.swc (e.g. a mocked or older compiler), the unchained loaderContext._compiler.rspack.experiments.swc throws TypeError: Cannot read properties of undefined (reading 'experiments') instead of returning null to fall back to Babel. The predecessor's optional chaining and @rspack/core resolution fallback are both gone, changing the failure mode from a Babel fallback to a build crash.

Suggested change
async function getSwcModule(loaderContext: LoaderContext): Promise<Swc | null> {
const projectRoot = getProjectRootPath(loaderContext) ?? process.cwd();
const isWebpack = isWebpackBackend(loaderContext);
if (!isWebpack) {
// happy path - rspack & exposed swc
// use optional chaining to avoid type errors when using parallel loader
if (loaderContext._compiler.rspack?.experiments?.swc) {
return loaderContext._compiler.rspack.experiments.swc;
}
// fallback to checking for `@rspack/core` installed in the project
// use optional chaining to avoid type errors when there is no experiments.swc
const rspackCorePath = safelyResolve('@rspack/core', projectRoot);
if (rspackCorePath && !isWebpack) {
const rspack = await importDefaultESM<typeof Rspack>(rspackCorePath);
return rspack.experiments?.swc ?? null;
}
if (!isWebpackBackend(loaderContext)) {
// Rspack exposes its bundled SWC, also to parallel loaders
return loaderContext._compiler.rspack.experiments.swc;
}
// fallback to checking for `@swc/core` installed in the project
// this can be in both webpack & rspack projects
const swcCorePath = safelyResolve('@swc/core', projectRoot);
// webpack - use `@swc/core` installed in the project
const swcCorePath = safelyResolve('@swc/core', loaderContext.rootContext);
if (!isWebpackBackend(loaderContext)) {
// Rspack exposes its bundled SWC, also to parallel loaders
return loaderContext._compiler.rspack?.experiments?.swc ?? null;
}
Details

Also raised here

Also raised at this location by persona javascript: getSwcModule throws instead of falling back when _compiler.rspack is missing — The loader now reads loaderContext._compiler.rspack.experiments.swc with no optional chaining and no fallback, so any context whose mocked _compiler lacks a rspack property throws TypeError: Cannot read properties of undefined (reading 'experiments') inside babelSwcLoader's try block and fails the module build. isWebpackBackend in this same file ends with "if both checks fail, we assume it's a Rspack compiler" and its own comment records that "parallel loader in Rspack has mocked compiler object without most props", so a context where neither _compiler.webpack.version nor loaderContext.webpack is present (the webpack thread-loader worker shape it was written for, or any future mock) is routed into the Rspack branch with no rspack on it. The predecessor resolved @rspack/core from the project and then @swc/core in that situation and returned null, which fell back to a Babel-only transform instead of erroring; that recovery path is gone. …

persona: senior-developer, javascript

@@ -60,8 +60,9 @@ function defaultModuleFilenameTemplateHandler(
return `inlined-${info.hash}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · path.normalize rewrites non-filesystem source names, not just Rspack's unjoined path

On Windows, path.normalize converts / to \ in non-filesystem source names like data: URIs, mangling them (e.g. data:text\javascript,...); SourceMapPlugin consumers that match on the original prefix stop matching.

Suggested change

Normalize only when path.isAbsolute(info.absoluteResourcePath) and pass pseudo-paths through unchanged.

  // use absolute path for all other modules - Rspack 2 joins it from the context
  // without resolving, e.g. `<context>/../../node_modules/...`
  if (path.isAbsolute(info.absoluteResourcePath)) {
    return path.normalize(info.absoluteResourcePath);
  }
  return info.absoluteResourcePath;
}
Details

persona: javascript

This branch was successfully deployed

1 active deployment
Preview — f7265b52 Deployed Nov 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant